package com.cleaningcloud.cld.controller;

import com.cleaningcloud.cld.domain.CldSettlement;
import com.cleaningcloud.cld.domain.dto.CldSettlementDto;
import com.cleaningcloud.cld.domain.vo.CldSettlementVo;
import com.cleaningcloud.cld.service.ICldSettlementService;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.web.page.TableDataInfo;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 结算管理Controller
 *
 * @author cleaningcloud
 * @date 2024-10-17
 */
@RestController
@RequestMapping("/settlement")
public class CldSettlementController extends BaseController {
    @Autowired
    private ICldSettlementService cldSettlementService;

    /**
     * 查询结算管理列表
     */
    @RequiresPermissions("cld:settlement:list")
    @GetMapping("/list")
    public TableDataInfo list(CldSettlementDto cldSettlement) {
        startPage();
        List<CldSettlementVo> list = cldSettlementService.selectCldSettlementList(cldSettlement);
        return getDataTable(list);
    }

    /**
     * 按项目区域分组统计
     */
    @RequiresPermissions("cld:settlement:list")
    @GetMapping("/groupByRegionList")
    public TableDataInfo groupByRegionList(CldSettlementDto cldSettlementDto) {
        startPage();
        List<CldSettlementVo> list = cldSettlementService.selectCldSettlementGroupRegionList(cldSettlementDto);
        return getDataTable(list);
    }


    /**
     * 结算头部统计
     */
    @GetMapping("/selectCldSettlementStatistics")
    public AjaxResult selectCldSettlementStatistics(CldSettlementDto cldSettlementDto) {
        return success(cldSettlementService.selectCldSettlementStatistics(cldSettlementDto));
    }

    /**
     * 导出结算管理列表
     */
    @RequiresPermissions("cld:settlement:export")
    @Log(title = "结算管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CldSettlementDto cldSettlement) {
        List<CldSettlementVo> list = cldSettlementService.selectCldSettlementList(cldSettlement);
        ExcelUtil<CldSettlementVo> util = new ExcelUtil<CldSettlementVo>(CldSettlementVo.class);
        util.exportExcel(response, list, "结算管理数据");
    }

    /**
     * 获取结算管理详细信息
     */
    @RequiresPermissions("cld:settlement:query")
    @GetMapping(value = "/{settlementId}")
    public AjaxResult getInfo(@PathVariable("settlementId") Long settlementId) {
        return success(cldSettlementService.selectCldSettlementBySettlementId(settlementId));
    }

    /**
     * 新增结算管理
     */
    @RequiresPermissions("cld:settlement:add")
    @Log(title = "结算管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CldSettlement cldSettlement) {
        return toAjax(cldSettlementService.insertCldSettlement(cldSettlement));
    }

    /**
     * 修改结算管理
     */
    @RequiresPermissions("cld:settlement:edit")
    @Log(title = "结算管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CldSettlement cldSettlement) {
        return toAjax(cldSettlementService.updateCldSettlement(cldSettlement));
    }

    /**
     * 删除结算管理
     */
    @RequiresPermissions("cld:settlement:remove")
    @Log(title = "结算管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{settlementIds}")
    public AjaxResult remove(@PathVariable Long[] settlementIds) {
        return toAjax(cldSettlementService.deleteCldSettlementBySettlementIds(settlementIds));
    }
}
